package com.cloudkinto.common.exception;


import com.cloudkinto.common.error.BaseErrorInfoInterface;
import com.cloudkinto.common.error.ErrorEnum;

import java.io.Serializable;

public class BizException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = 1L;


    /**
     * 错误码
     */
    private String errorCode = ErrorEnum.FAILURE.getResultCode();
    /**
     * 错误信息
     */
    private String errorMsg;

    /**
     * 消息模版占位符参数
     */
    private Object[] args;

    public BizException() {
        super();
    }

    public BizException(BaseErrorInfoInterface errorInfoInterface) {
        super(errorInfoInterface.getResultMsg());
        this.errorCode = errorInfoInterface.getResultCode();
        this.errorMsg = errorInfoInterface.getResultMsg();
    }

    public BizException(BaseErrorInfoInterface errorInfoInterface, Throwable cause) {
        super(errorInfoInterface.getResultMsg(), cause);
        this.errorCode = errorInfoInterface.getResultCode();
        this.errorMsg = errorInfoInterface.getResultMsg();
    }

    public BizException(String messageKey, Object... args) {
        super(messageKey);
//        this.messageKey = messageKey;
        this.errorMsg = messageKey;
        this.args = args;
    }

    public BizException(String errorMsg) {
        super(errorMsg);
        this.errorMsg = errorMsg;
    }

//    public BizException(String errorCode, String errorMsg) {
//        super(errorMsg);
//        this.errorCode = errorCode;
//        this.errorMsg = errorMsg;
//    }

    public BizException(String errorCode, String errorMsg, Throwable cause) {
        super(errorMsg, cause);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }


    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getMessage() {
        return errorMsg;
    }


    public Object[] getArgs() {
        return args;
    }


    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

}
